package cn.signalpha.modules.com.controller.api;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.modules.com.entity.UserWallet;
import cn.signalpha.modules.com.service.UserWalletService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_USER_NAME + "/wap/user/wallet")
@Api(value = "用户钱包", tags = "用户钱包")
public class ApiUserWalletController extends BaseController {

	private final UserWalletService userWalletService;

	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "")
	public R<IPage<UserWallet>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
		params.put("userId", getUser().getUserId());
		QueryWrapper<UserWallet> queryWrapper = userWalletService.selectUserWalletWrapper(params);
		return R.data(userWalletService.page(Condition.getPage(query), queryWrapper.lambda().orderByDesc(UserWallet::getId)));
	}

	@GetMapping("/amount")
	@ApiOperation(value = "统计", notes = "")
	public R amount(@ApiIgnore @RequestParam Map<String, Object> params) {
		params.put("userId", getUser().getUserId());
		return R.data(userWalletService.sumByParams(params));
	}

}
